﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary1.DAO;
using ClassLibrary1.Entity;


namespace Bilyteam_Website.Admin
{
    public partial class TeamsManager : System.Web.UI.Page
    {
        private Teams tem;
        private TeamsDAO temdao;
        public TeamsManager()
        {
            tem = new Teams();
            temdao = new TeamsDAO();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }

        }

        private void BindData()
        {
            dtlteams.DataSource = temdao.GetAll();
            dtlteams.DataBind();
        }

        protected void dtlteams_Edit(object source, DataListCommandEventArgs e)
        {
            Label lblID = e.Item.FindControl("lblID") as Label;
            Response.Redirect("TeamEdit.aspx?temsID=" + lblID.Text);
        }

        protected void btnadd_Click(object sender, EventArgs e)
        {
            try
            {
                tem.TeamName = txtteamname.Text;
                tem.TeamEmail = txtteamemail.Text;
                tem.TotalEmail = Int32.Parse(txttotalemail.Text);
                tem.Status = false;
                temdao.Insert(tem);
                BindData();

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }



        protected void dtlteams_Delete(object source, DataListCommandEventArgs e)
        {
            string id = dtlteams.DataKeys[e.Item.ItemIndex].ToString();
            temdao.Delete(Int32.Parse(id));
            dtlteams.EditItemIndex = -1;

            BindData();
        }
    }
}